<?php namespace Summer\Maphub\FormWidgets;

use Flash;
use Config;
use Backend\Classes\FormField;
use Backend\Classes\FormWidgetBase;
use Summer\Maphub\Models\Settings;

class Amap extends FormWidgetBase
{
    protected $defaultAlias = 'amap';

    public $mapWidth='100%';//宽
    public $mapHeight='400px';//高
    public $mapZoom=11;//地图层级
    public $longitudeCode='longitude';//经度字段
    public $latitudeCode='latitude';//纬度字段
    public $addressCode='address';//逆向地理编码字段

    public function render() {
        $this->prepareVars();
        return $this->makePartial('amap');
    }

    /**
     * @inheritDoc
     */
    public function init()
    {
        $this->fillFromConfig([
            'mapWidth',
            'mapHeight',
            'mapZoom',
            'longitudeCode',
            'latitudeCode',
            'addressCode',
        ]);
    }

    /**
     * Prepares the list data
     */
    public function prepareVars()
    {
        $maphub_settings= Settings::instance();
        $amapKay=$maphub_settings->amap_key;
        $amapJscode=$maphub_settings->amap_jscode;
        $this->vars['amapJscode'] = $amapJscode;
        $this->vars['amapKay'] = $amapKay;

        $this->vars['mapWidth'] = $this->mapWidth;
        $this->vars['mapHeight'] = $this->mapHeight;
        $this->vars['mapZoom'] = $this->mapZoom;
        $this->vars['longitudeCode'] = $this->longitudeCode;
        $this->vars['latitudeCode'] = $this->latitudeCode;
        $this->vars['addressCode'] = $this->addressCode;
    }



}
